package com.qst.express.controller;

import com.qst.commonUtils.result.R;
import com.qst.express.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author:CoolTiger
 * @title: OssController
 * @projectName springCloud_edu
 * @description: TODO
 * @date:2022/09/20/10:58:46
 **/

@Api("阿里云文件管理")
@CrossOrigin //跨域
@RestController
@RequestMapping("/e/fileoss")
public class OssController {
    @Autowired
    private OssService ossService;

    /**
     * 文件上传
     *
     * @param file
     */
    @ApiOperation("上传文件")
    @PostMapping("upload")
    public R upload(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file) {

        String uploadUrl = ossService.upload(file);
        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);

    }
}
